let Controller = {
	mounted() {
		this.initData();
	},
	activated() {
		this.initData();
		this.requestDetail();
	},
	methods: {
		initData() {
			const param = this.$route.query.data;
			this.Model.queryData = _.cloneDeep(param);
			this.Model.tabFormInline = [{
					label: '采购入库单号',
					value: this.Model.queryData.saleNumber,
				},
				{
					label: '单据状态',
					value: this.Model.queryData.aftersaleStatus,
				},
			];
			// this.requestDetail();
		},
		requestDetail() {
			const orderId = this.$route.query.data.id;
			if (orderId) this.$ajax
				.get(this.apiTest + `/sale/onSale/order/getGoodDetail/${orderId}`)
				.then(response => {
					const data = response.data;
					const result = data.result;
					this.Model.tableData = data.result.goodsInfoVos;
					this.Model.saleOrderGiftsList = result.saleOrderGiftsList;
					this.Model.saleOrderPayList = result.saleOrderPayList;
					this.Model.refundList = result.refundList;
					this.Model.saleLogList = result.saleLogList;
					this.Model.pager.pageTotal = data.pageTotal;
					this.Model.orderId = data.result.id;
					this.Model.originId = data.result.originId;
					this.setStepData(result.saleOrderStatusList, result.aftersaleStatus);
					this.Model.tableFormInline = [{
							label: '采购入库单号',
							value: '',
						},
						{
							label: '到货通知单',
							value: '',
						},
						{
							label: '供应商',
							value: ''
						},
						{
							label: '入库单类型',
							value: ''
						},
						{
							label: '入库仓库',
							value: ''
						},
						{
							label: '创建人',
							value: ''
						},
						{
							label: '操作人',
							value: ''
						},
						{
							label: '备注',
							value: ''
						}
					];
				})
				.catch(error => {
					this.$message.error('请求错误');
				});
		},
		toBarcodeDetail(row){
			//跳转条码详情
			const name = 'purchaseWarehousingBarcodeDetail';
			this.$router.push({
				name: name,
				query: {
					data: row
				}
			})
		},
		setStepData(list, status) {
			let activeStep = 0,
				step = [];
			for (let i = 0; i < list.length; i++) {
				if (list[i].code == status) activeStep = i;
				step.push({
					title: list[i].codeName,
					description: list[i].createTime
				})
			};
			this.Model.stepOption = {
				activeStep,
				step
			}
		},
		
		onDeleteExportData(){
			const list = this.Model.exportTableSelectList.map(item=>{
				return item.id
			});
			console.log(list)
		},
		onTableSelectionChange(val) {
			this.Model.exportTableSelectList = val;
			console.log(this.Model.exportTableSelectList);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = val;
		},
		toSearch(val) {
			console.log(val)
		},
		toClear(val) {
			this.Model.searchFromData = this.Model.defaultSearchFromData;
		},
		toExport(val) {
			console.log(val);
		},
		onTabChange(val) {
			switch (val) {
				case 1:
					break;
				case 2:
					break;
				case 3:
					break;
			}
		},
		toggleTableDetail(val) {
			const obj = this.Model[val];
			if (obj.flag === true) {
				this.Model[val].src = require('@/assets/img/icon_collapse.png');
				this.Model[val].flag = false;
			} else {
				this.Model[val].src = require('@/assets/img/icon_unfold.png');
				this.Model[val].flag = true;
			}
		},
		onDialogEdit(flag, val) {
			this.Model.editDialogFlag = flag;
			if (flag === false) return;
			const obj = this.Model[val];
			this.Model.editDialogFormData = _.cloneDeep(this.Model.defaultEditDialogFormData);
			this.getAddress();
		},
		changeAddress(val) {
			if (!val) {
				this.getAddress();
			}
		},
		getAddress() {
			const idcard = 4310555;
			this.$ajax.post(this.apiTest + `/sale/saleOrder/getAddressByIdCard/${idcard}`, {})
				.then(response => {
					const data = response.data;
					if (data.status == 200) {
						this.Model.addressList = data.result;
					}
				}).catch(err => {
					console.log(err)
				})
		},
		updateBaseSaleOrder() {
			const data = this.Model.editDialogFormData;
			let params;
			if (data.shippingMethod === '1') {
				params = {
					shippingMethod: data.shippingMethod,
					shipper: data.shipper,
					originChannel: data.originChannel,
					salesman: data.salesman,
				}
			} else {
				params = data;
			}
			this.$ajax.post(this.apiTest + `/sale/saleOrder/updateBaseSaleOrder`, params)
				.then(response => {
					const data = response.data;
					if (data.status == 200) {
						this.onDialogEdit(false);
						this.$message({
							type: 'success',
							message: '已成功保存'
						});
						this.requestDetail();
					} else {
						this.$message.error(data.msg);
					}
				}).catch(err => {
					this.$message.error(err);
					this.onDialogEdit(false);
				});
		},
	}
}
export default Controller;
